import ajax from '../../common/js/ajax'
import router from '@ohos.router'
export default {
    data: {
        swiperList: [],
        popularCategoryList: [],
        moreCategoryList: [],
        flashSaleGoodsList: [
            {id: 1, url: '/common/image/goods1.png', oldPrice: 4.98, newPrice: 3.58},
            {id: 2, url: '/common/image/goods2.png', oldPrice: 49.9, newPrice: 38.8},
            {id: 3, url: '/common/image/goods3.png', oldPrice: 8.5, newPrice: 3.9},
            {id: 4, url: '/common/image/goods4.png', oldPrice: 30, newPrice: 14.8}
        ],
        subsidyGoodsList:[
            {id: 5, url: '/common/image/goods5.png', price: 9.9},
            {id: 6, url: '/common/image/goods6.png', price: 9.9}
        ],
        specialGoodsList:[
            {id: 7, url: '/common/image/goods7.png', price: 17.8},
            {id: 8, url: '/common/image/goods8.png', price: 5.5}
        ],
    },
    onInit() {
        this.ajaxGetSwiper()
        this.ajaxGetPopularCategory()
        this.ajaxGetMoreCategory()
    },
    gotoCategory(categoryId){
        router.push({
            url: 'pages/category/category',
            params: {
                categoryId
            },
        })
    },
    ajaxGetSwiper() {
        ajax.get({
            url: 'http://124.71.79.186:8081/swiper/getList',
            success: resp => {
                if (resp.code === 200) {
                    this.swiperList = resp.data
//                    console.log(JSON.stringify(this.swiperList))
                }
            }
        })
    },
    ajaxGetPopularCategory() {
        ajax.get({
            url: 'http://124.71.79.186:8081/menu/findNav',
            success: resp => {
                if (resp.code === 200) {
                    this.popularCategoryList = resp.data.slice(0,10)
//                    console.log(JSON.stringify(this.popularCategoryList))

                }
            }
        })
    },
    ajaxGetMoreCategory() {
        ajax.get({
            url: 'http://124.71.79.186:8081/menu/findNav',
            success: resp => {
                if (resp.code === 200) {
                    this.moreCategoryList = resp.data.slice(10)
//                    console.log(JSON.stringify(this.moreCategoryList))

                }
            }
        })
    },
}



